<?php

/**
 * sfGuardUser form.
 *
 * @package    tattoo-2.0
 * @subpackage form
 * @author     Rommel M. Zamora
 * @version    SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class sfGuardUserForm extends PluginsfGuardUserForm
{
  public function configure()
  {
    unset(
      $this['last_login'],
      $this['created_at'],
      $this['updated_at'],
      $this['salt'],
      $this['algorithm'],
      $this['is_super_admin'],
      $this['permission_list']
    );

    $this->widgetSchema['password'] = new sfWidgetFormInputPassword();
    $this->widgetSchema['validate_password'] = new sfWidgetFormInputPassword();
    $this->widgetSchema['groups_list']->setOption('multiple',false);
    $this->widgetSchema['groups_list']->setLabel('Groups');

    $this->setValidators(array(
        'id'                =>  new sfValidatorChoice(
                                    array('choices' => array($this->getObject()->get('id')),
                                          'empty_value' => $this->getObject()->get('id'),
                                          'required' => false)),
        'first_name'        =>  new sfValidatorString(),
        'last_name'         =>  new sfValidatorString(),
        'position'         =>  new sfValidatorString(),
        'department'         =>  new sfValidatorString(),
        'email_address'     =>  new sfValidatorEmail(),
        'username'          =>  new sfValidatorPass(),
        'is_active'         =>  new sfValidatorPass(),
        'password'          =>  new sfValidatorPass(),
        'validate_password' =>  new sfValidatorPass()
    ));

    if($this->getObject()->isNew())
    {
    	$this->validatorSchema['password'] = new sfValidatorString();
    }

    $this->mergePostValidator(
        new sfValidatorSchemaCompare('password',
                sfValidatorSchemaCompare::EQUAL,
                'validate_password',
                array(),
                array('invalid'=>'Password do not matched')));

    $this->validatorSchema->setOption('allow_extra_fields', true);

  }

  public function getCustomError()
  {
      return FormCustomError::processCustomError($this);
  }
}